package com.healthbox.appointmentservice.DVO;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.healthbox.appointmentservice.entity.AppointmentLimit;
import com.healthbox.appointmentservice.entity.Hospital;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Null;
import java.time.LocalDate;
import java.time.LocalTime;

/**
 * @author pengpeng
 * @date 2022/5/12
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel(value = "预约限制信息", description = "查询预约限制信息，包括该预约限制信息名额剩余情况")
public class AppointmentLimitDVO {
    @ApiModelProperty(value = "预约限制编号", example = "1")
    private Long aLId;
    @ApiModelProperty(value = "预约限制对应日期", example = "2022-05-20")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
    private LocalDate date;
    @ApiModelProperty(value = "当前预约可检测时间段开始时间", example = "08:30:00")
    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "HH:mm:ss")
    private LocalTime startTime;
    @ApiModelProperty(value = "当前预约可检测时间段结束时间", example = "17:05:00")
    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "HH:mm:ss")
    private LocalTime endTime;
    @ApiModelProperty(value = "当前检测时间段可预约总人数", example = "100")
    private Integer maxNumber;
    @ApiModelProperty(value = "该检测限制所属机构对应编号", example = "1")
    private Long hospitalId;
    @ApiModelProperty(value = "检测机构名称", example = "天津医院")
    private String name;
    @ApiModelProperty(value = "检测机构地址", example = "天津津南")
    private String address;
    @ApiModelProperty(value = "检测机构对应管理员账号手机号", example = "19912345678")
    private String phone;
    @ApiModelProperty(value = "已预约人数", example = "1")
    private Integer currentNumber;

    public static AppointmentLimitDVO fromEntity(AppointmentLimit entity, Integer currentNumber){
        Hospital hospital = entity.getHospital();
        return AppointmentLimitDVO.builder()
                .aLId(entity.getALId())
                .date(entity.getDate())
                .startTime(entity.getStartTime())
                .endTime(entity.getEndTime())
                .maxNumber(entity.getMaxNumber())
                .hospitalId(hospital.getHospitalId())
                .name(hospital.getName())
                .address(hospital.getAddress())
                .phone(hospital.getPhone())
                .currentNumber(currentNumber)
                .build();
    }
}
